package net.sxnic.ugr.group.action;

import net.sxinfo.core.dao.Page;
import net.sxinfo.core.dao.hibernate3.SortCriteria;
import net.sxinfo.core.util.WebUtils;
import net.sxnic.comm.utils.PropertyUtil;
import net.sxnic.ugr.UgrActionSupport;
import net.sxnic.ugr.group.GroupManager;
import net.sxnic.ugr.role.Role;

import org.springframework.beans.factory.annotation.Autowired;


@SuppressWarnings("serial")
public class Browse extends UgrActionSupport {

    private Page groups;

    @Autowired
    private GroupManager groupManager;

    public String execute() throws Exception {
    	
		try {						
			checkRoles(Role.SYSTEM_ADMIN);
		
		    int pageNumber = WebUtils.getPageNumber(request);
		    int pageSize = PropertyUtil.findTableSize("firstbrowse.tabsize");
		
		
		    // 解析排序条件
		    SortCriteria sortCriteria = WebUtils.getSingleSortCriteria(request);	 
		    
		    groups = groupManager.getPage(pageNumber, pageSize, sortCriteria
		            .getPropertyName(), sortCriteria.isAscending());
					
		} catch (Exception e) {
			e.printStackTrace();
		}
        

        return SUCCESS;
    }

    public Page getGroups() {
        return groups;
    }

    /**
     * @param groupManager the groupManager to set
     */
    public void setGroupManager(GroupManager groupManager) {
        this.groupManager = groupManager;
    }
}
